export class Mutex {
    private isLocked: boolean = false

    // 锁定资源
    lock(): Promise<void> {
        return new Promise<void>(resolve => {
            const checkLock = () => {
                if (!this.isLocked) {
                    this.isLocked = true
                    resolve()
                } else {
                    setTimeout(checkLock, 10) // 10毫秒后重新检查锁状态
                }
            }
            checkLock()
        })
    }

    // 解锁资源
    unlock(): void {
        this.isLocked = false
    }
}
